<template>
	<view>
		 <!-- 手机 -->
	
	<PhoneIndex v-if="shouldRenderPhone" />

  
  
  <!-- 电脑 -->
  
   <WebIndex v-else />
	</view>
 
 
 
</template>

<script>
import WebIndex from 'pages/web/web'
import PhoneIndex from 'pages/phone/phone'

export default {
	

  components: {
    WebIndex,
    PhoneIndex
  },
  data() {
    return {
      shouldRenderPhone: false,
	 
    };
  },
  mounted() {
    // 初始化时检查渲染条件
    this.checkRenderCondition();

    // 监听窗口大小变化事件
    this.resizeHandler = () => {
		
      this.checkRenderCondition();
    };
    uni.onWindowResize(this.resizeHandler);
	// //初始化登录
	// uni.setStorage({
	// 	key:"token",
	// 	data:""
	// })
  },
  beforeDestroy() {
    // 组件销毁时移除监听
    uni.offWindowResize(this.resizeHandler);
  },
  methods: {
    checkRenderCondition() {
      const { windowWidth, windowHeight } = uni.getSystemInfoSync();
      // 计算屏幕比例
      const screenRatio = windowWidth / windowHeight;
      // 判断是否为竖屏
      const isPortrait = windowWidth < windowHeight;
      // 判断是否满足渲染手机端组件的条件
      this.shouldRenderPhone = isPortrait && screenRatio < 9 / 15;
    },
	onLoad: function (options) {
			setTimeout(function () {
				console.log('start pulldown');
			}, 1000);
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
		  console.log('refresh');
		  this.$eventBus.$emit('refresh-blog');
		  setTimeout(() => {
		    uni.stopPullDownRefresh();
		  }, 1000);
		},
	onNavigationBarButtonTap(e) {
	            // 点击添加按钮
	            if (e.index === 0) {
	                uni.showActionSheet({
	                    itemList: ['发表文章'],
	                    success: function (res) {
	                        if (!res.cancel) {
	                            if (res.tapIndex === 0) {
	                                console.log('用户点击了发表文章');
	                                // 在这里添加发表文章的逻辑
									uni.navigateTo({
										url:'/pages/blog/blog_editor'
									})
	                            }
	                        }
	                    },
	                    fail: function (err) {
	                        console.error('显示操作菜单失败:', err);
	                    }
	                });
	            }
	        }
	
  }
};
</script>

<style>
	
	.bubble {
	    position: fixed;
	    top: 50px; /* 根据实际情况调整位置 */
	    right: 10px;
	    background-color: #fff;
	    border: 1px solid #ccc;
	    padding: 10px;
	    border-radius: 5px;
	    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
	}
</style>